package com.hspedu.newData.dmsxl.数组.合并;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC1768交替合并字符串 {

    public String mergeAlternately(String word1, String word2) {
        int m = word1.length();
        int n = word2.length();

        StringBuilder sb = new StringBuilder();

        for (int i = 0,j = 0; i <m||j< n ; i++,j++) {
            String c1 = i < m ? word1.charAt(i)+"" : "";
            String c2 = j < n ? word2.charAt(j)+"" : "";
            sb.append(c1);
            sb.append(c2);
        }
        return sb.toString();
    }
}
